<extend name="Base/common"/>

<block name="side">

</block>
<block name="body">
    <php>
        query_user(array('avatar128','username','uid'));
    </php>
    <div class="col-md-12">
        <div class="row">
            <div class="col-md-9 weibo_main" style="margin-top: 10px">
                <div class="row">
                    <if condition="is_login()">
                        <div class="hot_post" style="margin-top: 0;padding-bottom: 10px">
                            <div class="row">
                                <div class="col-md-2">
                                    <script>
                                        var names ={$atwhousers};

                                        var names = $.map(names,function(value,i) {
                                            return {'id':i,'name':value.username,'pinyin':value.pinyin};
                                        });
                                        var at_config = {
                                            at: "@",
                                            data: names,
                                            tpl: "<li data-value='@${name}'>${name}</li>",
                                            show_the_at: true,
                                            search_key:'pinyin'
                                        };
                                        $(function(){
                                            $inputor = $('#weibo_content').atwho(at_config);
                                        })

                                    </script>
                                    <a href="{:U('UserCenter/Index/changeavatar')}" ><img src="{$self.avatar128}"
                                                                                          class="avatar-img"/></a>
                                </div>

                                <div class="col-md-6">
                                    <a style="font-size: 1.2em;width: 100%" title="{$self.username}" class="text-more" href="{$self.space_url}">{$self.username}</a>&nbsp;{$self.icons_html}
                                    <br/>积分：{$self.score}
                                    <br/>头衔：{$self.title}
                                </div>


                                 <div class="col-md-4 row">
                                     <div  style="margin: 10px;text-align: center">
                                     <div class="col-md-4">
                                            微博<br/>{$self.weibocount}
                                      </div>
                                    <div class="col-md-4">
                                     粉丝<br/>{$self.fans}
                                     </div>
                                    <div class="col-md-4">
                                         关注<br/>{$self.following}
                                    </div>
                                     </div>
                                </div>
                            </div>

                       </div>
                    </if>
                </div>

                <div class="row">
                    <div class="col-md-12" style="padding-top: 10px">
                        <p>
                            <img src="__IMG__/ad.png" style="width: 100%;"/>
                        </p>
                    </div>
                </div>
                <hr>
                <div id="weibo_list">
                    <volist name="list" id="weibo">

                        <div class="row" id="weibo_{$weibo.id}">
                            <div class="col-md-12">
                               <div style="padding-left: 16px; overflow: hidden;">
                                   <p>{$weibo.content}</p>

                                    <p>

                                        <span class="text-primary">{$weibo.create_time|friendlyDate}</span>
                                        <a class="pull-right text-primary weibo-comment-link" href="#"  data-weibo-id="{$weibo.id}">
                                            <php>
                                                $weiboCommentTotalCount = $weibo['comment_count'];
                                            </php>
                                            <include file="commentText"/>
                                        </a>
                                    </p>

                                    <div class="row weibo-comment-list" style="display: none;" data-weibo-id="{$weibo.id}">
                                        <div class="col-md-12">
                                            <div class="light-jumbotron" style="padding: 1em 2em;">
                                                <div class="weibo-comment-container">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                   </volist>
               </div>
         </div>
            <div class="col-md-3">

                <div>
                    {:hook('Rank')}

                    {:W('UserList/lists',array('forum_id'=>$forum_id))}
                </div>
            </div>

        </div>
    </div>
</block>

<block name="script">
    <script type="text/javascript" src="__STATIC__/oneplus/js/ext/atwho/atwho.js"></script>
    <link type="text/css" rel="stylesheet" href="__STATIC__/oneplus/js/ext/atwho//atwho.css"/>
    <script src="__JS__/weibo.js"></script>
    <script>
        $(function () {
            var noMoreNextPage = false;
            var isLoadingWeibo = false;
            var currentPage = 1;

            //点击评论之后载入评论
            $(document).on('click', '.weibo-comment-link', function (e) {
                var weibo_id = $(this).attr('data-weibo-id');
                var weiboCommentList = $('#weibo_' + weibo_id + ' .weibo-comment-list');
                if (weiboCommentList.is(':visible')) {
                    hideWeiboCommentList(weiboCommentList);
                } else {
                    showWeiboCommentList(weiboCommentList);
                }


                //取消默认动作
                e.preventDefault();
                return false;
            });

            $('.weibo-comment-link').click();



            function isLoadMoreVisible() {
                var visibleHeight = $(window.top).height();
                var loadMoreOffset = $('#load_more').offset();
                return visibleHeight + window.scrollY > loadMoreOffset.top;
            }


            function showWeiboCommentList(weiboCommentList) {
                //判断是否已经载入
                var weiboContainer = $('.weibo-comment-container', weiboCommentList);
                var loaded = weiboCommentList.attr('data-weibo-comment-loaded');

                //如果已经载入，只要显示即可
                if (loaded) {
                    weiboCommentList.show();

                    return;
                }

                //显示“正在加载评论”
                weiboContainer.html('<span class="text-muted">正在加载...</span>');
                weiboCommentList.show();

                //通过服务器载入评论列表
                reloadWeiboCommentList(weiboCommentList);
            }

            function hideWeiboCommentList(weiboCommentList) {
                weiboCommentList.hide();
            }

        })
    </script>
</block>
